#ifndef __GF_SPI_H
#define __GF_SPI_H

#include <linux/types.h>
#include <linux/notifier.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/wakelock.h>
/**********************************************************/
//#define GF_DEBUG
/*#undef  GF_DEBUG*/

#ifdef  GF_DEBUG
#define gf_dbg(fmt, args...) do { \
        pr_warn("gf:" fmt, ##args);\
    } while (0)
#define FUNC_ENTRY()  pr_warn("gf:%s, entry\n", __func__)
#define FUNC_EXIT()  pr_warn("gf:%s, exit\n", __func__)
#else
#define gf_dbg(fmt, args...)
#define FUNC_ENTRY()
#define FUNC_EXIT()
#endif
#define gf_err(fmt, args...) do { \
        pr_err("gf:" fmt, ##args);\
    } while (0)
#define gf_info(fmt, args...) do { \
        pr_warn("gf:" fmt, ##args);\
    } while (0)

enum FP_MODE{
    GF_IMAGE_MODE = 0,
    GF_KEY_MODE,
    GF_SLEEP_MODE,
    GF_FF_MODE,
    GF_DEBUG_MODE = 0x56
};

struct gf_key {
    unsigned int key;
    int value;
};


struct gf_key_map
{
    char *name;
    unsigned short val;
};

#define  GF_IOC_MAGIC         'G'
#define  GF_IOC_DISABLE_IRQ	_IO(GF_IOC_MAGIC, 0)
#define  GF_IOC_ENABLE_IRQ	_IO(GF_IOC_MAGIC, 1)
#define  GF_IOC_SETSPEED    _IOW(GF_IOC_MAGIC, 2, unsigned int)
#define  GF_IOC_RESET       _IO(GF_IOC_MAGIC, 3)
#define  GF_IOC_COOLBOOT    _IO(GF_IOC_MAGIC, 4)
#define  GF_IOC_SENDKEY    _IOW(GF_IOC_MAGIC, 5, struct gf_key)
#define  GF_IOC_CLK_READY  _IO(GF_IOC_MAGIC, 6)
#define  GF_IOC_CLK_UNREADY  _IO(GF_IOC_MAGIC, 7)
#define  GF_IOC_PM_FBCABCK  _IO(GF_IOC_MAGIC, 8)
#define  GF_IOC_POWER_ON   _IO(GF_IOC_MAGIC, 9)
#define  GF_IOC_POWER_OFF  _IO(GF_IOC_MAGIC, 10)

#define  GF_IOC_MAXNR    11

//#define AP_CONTROL_CLK       1
#define  USE_PLATFORM_BUS     1
//#define  USE_SPI_BUS    1
#define GF_FASYNC   1    /*If support fasync mechanism.*/
struct gf_dev {
    dev_t devt;
    struct list_head device_entry;
#if defined(USE_SPI_BUS)
    struct spi_device *spi;
#elif defined(USE_PLATFORM_BUS)
    struct platform_device *spi;
#endif
    struct clk *core_clk;
    struct clk *iface_clk;
    struct wake_lock irq_wakelock;

    struct input_dev *input;
    /* buffer is NULL unless this device is open (users > 0) */
    unsigned users;
    signed irq_gpio;
    signed reset_gpio;
    signed pwr_gpio;
    int irq;
    int irq_enabled;
    int clk_enabled;
#ifdef GF_FASYNC
    struct fasync_struct *async;
#endif
    struct notifier_block notifier;
    char device_available;
    char fb_black;
};

int gf_pins_request(struct gf_dev* gf_dev);
int gf_pins_status_init(struct gf_dev * gf_dev);
void gf_cleanup(struct gf_dev *gf_dev);

int gf_power_on(struct gf_dev *gf_dev);
int gf_power_off(struct gf_dev *gf_dev);

int gf_hw_reset(struct gf_dev *gf_dev, unsigned int delay_ms);
int gf_irq_num(struct gf_dev *gf_dev);
void gf_enable_irq(struct gf_dev *gf_dev);
void gf_disable_irq(struct gf_dev *gf_dev);

#endif /*__GF_SPI_H*/
